package com.donger.business.handler;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.security.authentication.event.AbstractAuthenticationFailureEvent;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.stereotype.Component;


/**
 * 登陆失败
 */
@Component
@Slf4j
public class AuthenticationFailureHandler implements ApplicationListener<AbstractAuthenticationFailureEvent> {
    @Override
    public void onApplicationEvent(AbstractAuthenticationFailureEvent event) {
        Authentication authentication = (Authentication) event.getSource();
        AuthenticationException exception = event.getException();
        log.error("用户: {}登陆失败，异常: {}",authentication.getPrincipal(),exception.getLocalizedMessage());
    }
}
